<template>
  <div class="add-goods">
    <!-- 面包屑 -->
    <div class="title">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/goods' }"
          >商品管理</el-breadcrumb-item
        >
        <el-breadcrumb-item>商品添加</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!-- 信息填入 -->
    <div class="infomation">
      <el-form
        :model="goodsForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="类目选择" prop="category">
          <el-button type="primary">类目选择</el-button>
        </el-form-item>
        <el-form-item label="商品名称" prop="title">
          <el-input v-model="goodsForm.title"></el-input>
        </el-form-item>
        <el-form-item label="商品价格" prop="price">
          <el-input v-model="goodsForm.price"></el-input>
        </el-form-item>
        <el-form-item label="商品数量" prop="num">
          <el-input v-model="goodsForm.num"></el-input>
        </el-form-item>
        <el-form-item label="添加时间" prop="time">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="goodsForm.time"
            style="width: 150px"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="商品卖点" prop="name">
          <el-input v-model="goodsForm.sellPoint"></el-input>
        </el-form-item>
        <el-form-item label="商品图片" prop="name">
          <el-button type="primary">上传</el-button>
        </el-form-item>
        <el-form-item label="商品描述" prop="name"
          ><el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="goodsForm.sellPoint"
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >确定</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      goodsForm: {
        title: "", //商品名称
        price: "", //商品价格
        num: "", //商品数量
        sellPoint: "", //商品卖点
        image: "", //商品图片
        descs: "", //商品描述
        category: "", //类目规格
        time: "",
      },
      rules: {
        title: [
          { required: true, message: "请输入商品名称", trigger: "blur" },
          { min: 1, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        price: [{ required: true, message: "请输入商品价格", trigger: "blur" }],
        num: [
          { required: true, message: "请输入商品数量", trigger: "blur" },
          { min: 1, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style lang='less' scpoed>
.add-goods {
  margin: 20px;
  .title {
    padding: 10px;
    background-color: #fff;
    border: 1px solid #eee;
    margin-bottom: 20px;
  }
  .infomation {
    padding: 20px;
    padding-right: 30px;
    background-color: #fff;
    border: 1px solid #eee;
  }
}
</style>